<template>
	<view>
	<!-- <my-goods :goodsList='goodsList'></my-goods> -->
   
    <block  v-for="(item,i) in goodsList" :key='i'>
      <my-goods  :item='item'></my-goods>
    </block>
	</view>
</template>

<script>
	export default {
		data() {
			return {
        total:'',
        flag:true,
            goodsList:[],
            queryObj:{
            query:'',
            cid:'',
            pagenum:1,
            pagesize:10
        }
			};
		},
    onLoad(options){
      this.queryObj.query=options.query||''
      this.getGoodsList()
    },
    methods:{
     async getGoodsList(cb){
      const { data: res } = await uni.$http.get('/api/public/v1/goods/search', this.queryObj)
          if (res.meta&&res.meta.status&&res.meta.status !== 200) return uni.$showMsg()
          console.log('111111',res)
          this.total=res.message.total/this.queryObj.pagesize
          this.goodsList=[...this.goodsList,...res.message.goods]
          this.flag=true
          //请求完数据后执行函数停止下拉刷新
          cb&&cb()
      },
    
    },
    onReachBottom(){
   if(this.flag){
     this.flag=false
     this.queryObj.pagenum++;
     this.getGoodsList()
     if(this.queryObj.pagenum>this.queryObj.total){
       return uni.$showMsg('数据加载完毕')
     }
   }
    },
    onPullDownRefresh(){
       this.flag=true;
       this.total='';
       this.queryObj.pagenum=1;
       this.goodsList=[];
       this.getGoodsList(()=>{
         uni.stopPullDownRefresh()
       })
    }
	}
</script>

<style lang="scss">


</style>
